from sqlalchemy import Integer, Column, DateTime, Boolean, func, Float

from sqlalchemy_tool.manager import Manager
from sqlalchemy_tool.meta_class import ModelMetaClass
from sqlalchemy_tool.config import Base


class Model(Base, metaclass=ModelMetaClass):
    """模型根类"""
    __abstract__ = True

    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    add_time = Column(DateTime, comment='添加时间', default=func.now())
    update_time = Column(DateTime, comment='修改时间', default=func.now(), onupdate=func.now())
    is_enable = Column(Boolean, comment='是否可用', default=False)
    order_num = Column(Float, comment='排序值', default=100)

    @classmethod
    def objects_(cls) -> Manager:
        return Manager(model_class=cls)

    @property
    def objects(self) -> Manager:
        return Manager(model_obj=self)
